package com.scaffold.catalog.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import wangjg.commons.page.Page;

import com.scaffold.catalog.entity.Catalog;
import com.scaffold.springmvc.dao.BasicBizDAO;

@Repository
public class CatalogDAO extends BasicBizDAO<Catalog,Long>{

	public List<Catalog> findByParentId(Long parentId) {
		return this.findListByProperty("parentId", parentId);
	}
	
	public List<Catalog> pageQuery(Page page, String name, Long parentId, String keyword) {
		DetachedCriteria criteria = DetachedCriteria
				.forClass(this.persistentClass);
		if (name != null) {
			criteria.add(Restrictions.eq("name", name));
		}
		if (parentId != null) {
			criteria.add(Restrictions.eq("parentId", parentId));
		}
		criteria.addOrder(Order.desc("id"));
		return this.findByCriteria(criteria, page);
	}
}
